﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TheGunningMan
{
    namespace MdlPlugin
    {
        using Gunningine;

        /// <summary>
        /// Mdl header struct.
        /// </summary>
        internal struct MdlHeader
        {
            public Int32 ident;
            public Int32 version;
            public Vector3 scale;
            public Vector3 translation;
            public Int32 skinWidth;
            public Int32 skinHeight;
            public Int32 numSkins;
            public Int32 numVerts;
            public Int32 numTris;
            public Int32 numFrames;

            /// <summary>
            /// Render info: we need to scale up to pow-2, and this will
            /// affect texture coords.
            /// </summary>
            public Int32 renderWidth;
            public Int32 renderHeight;
            public Int32 numAdjustedVerts;
        }

        /// <summary>
        /// Mdl texture struct.  Mdl files include texture data.
        /// </summary>
        internal struct MdlSkin
        {
            public Int32 width;
            public Int32 height;
            public Int32 numFrames;
            public List<byte[]> frames;
            public List<float> times;

            /// <summary>
            /// Constructor.
            /// </summary>
            /// <param name="width"></param>
            /// <param name="height"></param>
            public MdlSkin(int width, int height)
            {
                this.width = width;
                this.height = height;
                this.numFrames = -1;
                this.frames = new List<byte[]>();
                this.times = new List<float>();
            }
        }

        /// <summary>
        /// Mdl texture coordinate.
        /// </summary>
        internal struct MdlTexCoord
        {
            public Int32 onSeam;
            public Int32 s, t;
        }

        /// <summary>
        /// Mdl triangle.
        /// </summary>
        internal struct MdlTriangle
        {
            public Int32 facesFront;
            public Int32[] vertices;

            /// <summary>
            /// Constructor.
            /// </summary>
            /// <param name="dummy">Oh C# why are you so dumb?</param>
            public MdlTriangle(Int32 faceDefault)
            {
                this.facesFront = faceDefault;
                this.vertices = new Int32[3];
            }
        }

        /// <summary>
        /// Mdl vertex struct.
        /// </summary>
        internal struct MdlVertex
        {
            public byte x, y, z;
        }

        /// <summary>
        /// Mdl frame data.
        /// </summary>
        internal struct MdlFrame
        {
            public string name;
            public MdlVertex[] vertices;
            public MdlVertex bbMin, bbMax;

            /// <summary>
            /// Constructor.
            /// </summary>
            /// <param name="numVerts"></param>
            public MdlFrame(int numVerts)
            {
                this.name = null;
                this.vertices = new MdlVertex[numVerts];
                this.bbMin = new MdlVertex();
                this.bbMax = new MdlVertex();
            }
        }
    }
}
